﻿using System;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Think.Problems.Solitaire;
using Con = System.Console;

namespace Think.Console
{
    class Program
    {
        static void Main(string[] args)
        {

        }

        static void RunMany()
        {
            var random = new Random();

            int games = 1000;
            int wins = 0;

            for (int i = 1; i < games; i++)
            {
                Con.ForegroundColor = ConsoleColor.Gray;

                var state = new SolitaireState(i);
                var actions = state.Actions();
                var renderer = new SolitaireConsoleRenderer(state);

                var timeout = new Stopwatch();
                timeout.Start();

                var success = true;

                while (actions.Any())
                {
                    var bestAction = actions.OrderByDescending(j => j.Value).First();
                    state.Act(bestAction);

                    actions = state.Actions();

                    if (timeout.Elapsed > TimeSpan.FromSeconds(0.2))
                    {
                        success = false;
                        break;
                    }
                }

                if (success)
                {
                    wins++;
                    Con.ForegroundColor = ConsoleColor.Green;
                    Con.Write("Solved {0}!", i);
                    Con.ForegroundColor = ConsoleColor.Gray;
                    Con.WriteLine(" Time={0}", timeout.Elapsed);
                }
                //else
                //{
                //    Con.Clear();

                //    Con.WriteLine("Seed={0}", i);
                //    renderer.Dump();
                //    Con.ReadLine();
                //}
                

            }

            Con.WriteLine("{0}/{1} ({2}%)", wins, games, (wins / (double)games) * 100.0);

            Con.ReadLine();
        }
    }
}
